package com.zhangyu.shadow.repair.delegate.maintain;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

import com.zhangyu.shadow.repair.R;

/**
 * @author zhangyu
 * @date 2019/3/19
 */
public class InputPhoneNumberDialog extends Dialog {
    public InputPhoneNumberDialog(Context context, final OnActionListener listener) {
        super(context);
        setTitle("提交手机号码");
        View view = LayoutInflater.from(context).
                inflate(R.layout.dialog_input_phone_number, null);
        final EditText etNumber = view.findViewById(R.id.et_phone_number);
        view.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onDone("");
                    dismiss();
                }
            }
        });
        view.findViewById(R.id.btn_commit).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onDone(etNumber.getText().toString());
                    dismiss();
                }
            }
        });
        setCanceledOnTouchOutside(false);
        setContentView(view);
    }

    public interface OnActionListener {
        void onDone(String number);
    }
}
